package com.xiaoxi.commandmode.command;

import java.util.Stack;

/**
 * @Author xiaoxi
 * @ProjectName design_mode
 * @PackageName com.xiaoxi.commandmode.command
 * @ClassName MacroCommand
 * @Description TODO
 * @Date 2023/4/15 11:07
 * @Version 1.0
 */
public class MacroCommand implements Command {

    // 命令的集合
    private Stack<Command> commands = new Stack();

    @Override
    public void execute() {
        for (Command next : commands) {
            next.execute();
        }
    }

    // 添加命令
    public void append(Command command) {
        if (command != this) {
            commands.add(command);
        }
    }

    // 撤销
    public void undo() {
        if(!commands.isEmpty()) {
            commands.pop();
        }
    }

    // 清除
    public void clear() {
        commands.clear();
    }

}
